#ifndef __MIFARE_H
#define __MIFARE_H

#include <string.h>
#include "include/zkrd522.h"
#include "include/spi.h"
#include "include/delay.h"
#define PICC_AUTHENT1A        0x60               //验证A密钥
#define PICC_AUTHENT1B        0x61               //验证B密钥
#define PICC_READ             0x30               //读块
#define PICC_WRITE            0xA0               //写块
#define PICC_DECREMENT        0xC0               //扣款
#define PICC_INCREMENT        0xC1               //充值
#define PICC_RESTORE          0xC2               //调块数据到缓冲区
#define PICC_TRANSFER         0xB0               //保存缓冲区中数据
#define PICC_RESET            0xE0               //复位


#define PICC_AUTHENT_D 0x0A				//验证密钥
#define CREATE_APPLICATION 0xCA			//创建应用
#define GET_APPLICATION_IDS 0x6A		//获取PICC中活动的应用标识符
#define SELECT_APPLICATION 0x5A 		//选择一个应用
#define GET_FILE_IDS 0x6F						//获取应用中所有文件标识符
#define CREATE_DATAFILE 0xCD 				//创建普通数据文件
#define READ_DATA 0xBD 						//读取文件数据
#define WRITE_DATA 0x3D						//写文件数据
#define CHANGE_KEY 0xC4						//修改密钥


#define PLAIN_COMMUNICATION 0x00	//明文通信
#define	PLAIN_COMMUNICATION_DES 0x01	//加密明文通信
#define PLAIN_COMMUNICATION_FULLY 0x03//加密通信

typedef   signed   char int8_t;
typedef unsigned          char uint8_t;
typedef unsigned short     int uint16_t;
typedef unsigned           int uint32_t;
int8_t pcd_auth_state(uint8_t auth_mode, uint8_t block, uint8_t *psnr, uint8_t *pkey);
int8_t pcd_write_block(unsigned char b_num, unsigned char *block_inf);
int8_t pcd_read_block(uint8_t b_num, uint8_t *block_inf);
int8_t pcd_auth_state(uint8_t auth_mode, uint8_t block, uint8_t *psnr, uint8_t *pkey);
//int8_t pcd_write_block(unsigned char b_num, unsigned char *block_inf);
int8_t pcd_set_value_block(unsigned char b_num, unsigned char *block_inf);
int8_t pcd_transfer_block(unsigned char b_num);
int8_t pcd_value(unsigned char dd_mode, unsigned char addr, unsigned char *pValue);
char pcd_bak_value(unsigned char sourceaddr, unsigned char goaladdr);
int8_t desocd_transmission(uint8_t *length,uint8_t *buf);
#endif